Skip to content

Keep the RFC 2396 regexps within the match cache - #271

Merged
mame merged 2 commits into
ruby:masterfrom
mame:uri-linear-regexp
Nov 25, 2026
Merged

mame merged 2 commits into
ruby:masterfrom
mame:uri-linear-regexp

Conversation

@mame

@mame mame commented Nov 17, 2026

Copy link
Copy Markdown
Member

The bounded repeats {2}, {1,3} and {1,4} inside other repeats keep the regexp match cache from being used, and URI.extract and URI.regexp took quadratic time on some inputs. Spell them out with optional atoms so that the regexps satisfy Regexp.linear_time?.

Reported-by: Bilal Karaaslan (https://hackerone.com/bilalkaraaslan)

The bounded repeats {2}, {1,3} and {1,4} inside other repeats keep the
regexp match cache from being used, and URI.extract and URI.regexp took
quadratic time on some inputs.  Spell them out with optional atoms so
that the regexps satisfy Regexp.linear_time?.

Reported-by: Bilal Karaaslan (https://hackerone.com/bilalkaraaslan)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mame
mame requested a review from nobu November 17, 2026 04:40
JRuby and TruffleRuby return false from Regexp.linear_time? for these
regexps, and CRuby 3.2 does not apply the match cache to look-arounds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mame
mame merged commit 006e41d into ruby:master Nov 25, 2026
26 checks passed
@mame
mame deleted the uri-linear-regexp branch November 25, 2026 13:31
matzbot pushed a commit to ruby/ruby that referenced this pull request Nov 25, 2026
(ruby/uri#271)

* Keep the RFC 2396 regexps within the match cache

The bounded repeats {2}, {1,3} and {1,4} inside other repeats keep the
regexp match cache from being used, and URI.extract and URI.regexp took
quadratic time on some inputs.  Spell them out with optional atoms so
that the regexps satisfy Regexp.linear_time?.

Reported-by: Bilal Karaaslan (https://hackerone.com/bilalkaraaslan)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Run the linear_time? test only on CRuby 3.3+

JRuby and TruffleRuby return false from Regexp.linear_time? for these
regexps, and CRuby 3.2 does not apply the match cache to look-arounds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

ruby/uri@006e41d2fa

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant